Skip to content

Conversation

marysha-openai
Copy link
Contributor

Summary

  • capture the x-request-id from streamed OpenAI Responses API calls and attach it to the final response before tracing
  • ensure traced streaming responses persist the request id when tracing data is recorded
  • add a regression test that stubs the streamed client and verifies the ResponseSpanData holds the request id after Runner.run_streamed

Testing

  • make format
  • make lint
  • make mypy
  • make tests
  • uv run pytest tests/test_agent_tracing.py::test_streamed_response_request_id_recorded

https://chatgpt.com/codex/tasks/task_i_68d5e042271c832e806c32939e01610d

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change is fine, but accessing openai._models may be a bit fragile in the long run. We may want to move the function from _models module for safety (meaning making changes to openai package first).

from typing import TYPE_CHECKING, Any, Literal, cast, overload

from openai import NOT_GIVEN, APIStatusError, AsyncOpenAI, AsyncStream, NotGiven
from openai._models import add_request_id
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accessing _models module may be broken when the underlying "openai" package makes breaking changes in the future. We've been dealing with incompatible changes on the "openai" package side several time. Accessing underscore prefixed (kind of private) module could be even more risky in the long run.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea makes sense - i'll look into doing this differently later today

@seratch seratch marked this pull request as draft September 26, 2025 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants